﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using sorochinska_kl.Models;

namespace sorochinska_kl.Controllers
{
    public class SkillDevPlanController : Controller
    {
        private UsersContext db = new UsersContext();

        //
        // GET: /SkillDevPlan/

        public ActionResult Index()
        {
            var skilldevplans = db.SkillDevPlans.Include(s => s.Assessment).Include(s => s.SkillLevel).Include(s => s.Status);
            return View(skilldevplans.ToList());
        }

        //
        // GET: /SkillDevPlan/Details/5

        public ActionResult Details(int id = 0)
        {
            SkillDevPlan skilldevplan = db.SkillDevPlans.Find(id);
            if (skilldevplan == null)
            {
                return HttpNotFound();
            }
            return View(skilldevplan);
        }

        //
        // GET: /SkillDevPlan/Create

        public ActionResult Create()
        {
            ViewBag.AssessmentID = new SelectList(db.Assessments, "AssessmentID", "Name");
            ViewBag.SkillLevelID = new SelectList(db.SkillLevels, "SkillLevelID", "Name");
            ViewBag.StatusID = new SelectList(db.GeneralStatuses, "StatusID", "Name");
            return View();
        }

        //
        // POST: /SkillDevPlan/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(SkillDevPlan skilldevplan)
        {
            if (ModelState.IsValid)
            {
                db.SkillDevPlans.Add(skilldevplan);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.AssessmentID = new SelectList(db.Assessments, "AssessmentID", "Name", skilldevplan.AssessmentID);
            ViewBag.SkillLevelID = new SelectList(db.SkillLevels, "SkillLevelID", "Name", skilldevplan.SkillLevelID);
            ViewBag.StatusID = new SelectList(db.GeneralStatuses, "StatusID", "Name", skilldevplan.StatusID);
            return View(skilldevplan);
        }

        //
        // GET: /SkillDevPlan/Edit/5

        public ActionResult Edit(int id = 0)
        {
            SkillDevPlan skilldevplan = db.SkillDevPlans.Find(id);
            if (skilldevplan == null)
            {
                return HttpNotFound();
            }
            ViewBag.AssessmentID = new SelectList(db.Assessments, "AssessmentID", "Name", skilldevplan.AssessmentID);
            ViewBag.SkillLevelID = new SelectList(db.SkillLevels, "SkillLevelID", "Name", skilldevplan.SkillLevelID);
            ViewBag.StatusID = new SelectList(db.GeneralStatuses, "StatusID", "Name", skilldevplan.StatusID);
            return View(skilldevplan);
        }

        //
        // POST: /SkillDevPlan/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(SkillDevPlan skilldevplan)
        {
            if (ModelState.IsValid)
            {
                db.Entry(skilldevplan).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.AssessmentID = new SelectList(db.Assessments, "AssessmentID", "Name", skilldevplan.AssessmentID);
            ViewBag.SkillLevelID = new SelectList(db.SkillLevels, "SkillLevelID", "Name", skilldevplan.SkillLevelID);
            ViewBag.StatusID = new SelectList(db.GeneralStatuses, "StatusID", "Name", skilldevplan.StatusID);
            return View(skilldevplan);
        }

        //
        // GET: /SkillDevPlan/Delete/5

        public ActionResult Delete(int id = 0)
        {
            SkillDevPlan skilldevplan = db.SkillDevPlans.Find(id);
            if (skilldevplan == null)
            {
                return HttpNotFound();
            }
            return View(skilldevplan);
        }

        //
        // POST: /SkillDevPlan/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            SkillDevPlan skilldevplan = db.SkillDevPlans.Find(id);
            db.SkillDevPlans.Remove(skilldevplan);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}